from typing import List, Optional
from pydantic import BaseModel, Field


# 图书模型
class Book(BaseModel):
    book_id: int = Field(..., description="图书ID")
    title: str = Field(..., description="书名")
    author: str = Field(..., description="作者")
    translator: Optional[str] = Field(None, description="译者")
    language: Optional[str] = Field("中文", description="语言")
    intro: Optional[str] = Field(None, description="图书简介")
    cover_url: Optional[str] = Field(None, description="封面图片链接")
    good_rating: Optional[int] = Field(0, description="好评数")
    fair_rating: Optional[int] = Field(0, description="一般评价数")
    poor_rating: Optional[int] = Field(0, description="差评数")
    rating: Optional[float] = Field(0.0, description="综合评分")
    rating_count: Optional[int] = Field(0, description="总评价人数")
    total_chapters: Optional[int] = Field(None, description="总章节数")
    price: Optional[float] = Field(None, description="价格")
    publish_time: Optional[str] = Field(None, description="出版时间")
    reading_count: Optional[int] = Field(0, description="正在阅读人数")
    main_categories: Optional[List[str]] = Field(
        default_factory=list, description="主分类"
    )
    sub_categories: Optional[List[str]] = Field(
        default_factory=list, description="子分类"
    )


# 图书响应模型
class BookResponse(BaseModel):
    message: str = Field("查询成功", description="响应消息")
    """响应消息，默认值为查询成功"""
    book_data: Optional[Book] = Field(..., description="图书数据")
    """单个图书数据"""


# 图书列表响应模型
class BookListResponse(BaseModel):
    message: str = Field("查询成功", description="响应消息")
    books_list: List[Book] = Field(default_factory=list, description="图书列表")
    total: int = Field(0, description="总数量")
    page: int = Field(1, description="当前页码")
    limit: int = Field(10, description="每页数量")


# 所有主分类响应模型
class MainCategoryResponse(BaseModel):
    message: str = Field("获取主分类成功", description="响应消息")
    count: int = Field(0, description="主分类数量")
    """主分类数量"""
    main_category_list: List[str] = Field(
        default_factory=list, description="主分类列表"
    )
    """主分类列表"""
